<?php
class CPyramidMember extends Zend_Db_Table
{
	protected $_name = '';
	protected $_primary = '';
	
	public function __construct()
	{
		$this->_name = R_PRE . 'pyramid_member';
		$this->_primary = 'member_id';
		parent::__construct();
	}
	
	public function add($row)
	{
		$db = $this->getAdapter();
		$where = $db->quoteInto('facebook_id = ?', $row['facebook_id']);
		$sql = 'select * from ' . $this->_name . ' where ' . $where;
		$result = $db->fetchAll($sql);
		if (count($result) > 0) {
			return 0;
		}
		$accountModel = new CPyramidMemberAccount();
		$accountModel->insert(array('facebook_id'=>$row['facebook_id'], 'amount'=>'0.00', 'last_change_time'=>time()));
		return $this->insert($row);
	}
}